package user;

import grails.test.*

class PetianoTests extends GrailsUnitTestCase {
 	private String NAME_1 = "João"
	private String SOBRENOME_1 = "Silva"
	private String LOGIN_1 = "joaosilva15"
	private String PASSWORD_1 = "abc123"
	private String EMAIL_1 = "joaosilva15@dsc.ufcg.edu.br"
	private Date ADMISSION_1 = new Date()
	private double CRE_1 = 7.2
	private boolean EH_BOLSISTA_1 = true
	private int PERIODO_1 = 6
	
	
	protected void setUp() {
		super.setUp()
	}
	
	protected void tearDown() {
		super.tearDown()
	}
	
	void testValues() {
		Petiano t = new Petiano(nome:NAME_1, sobrenome:SOBRENOME_1, login:LOGIN_1,
		password:PASSWORD_1, email:EMAIL_1, CRE:CRE_1, ehBolsista:EH_BOLSISTA_1, periodo:PERIODO_1)
		assertEquals NAME_1, t.nome
		assertEquals SOBRENOME_1, t.sobrenome
		assertEquals LOGIN_1, t.login
		assertEquals PASSWORD_1, t.password
		assertEquals EMAIL_1, t.email
		assertEquals CRE_1, t.CRE
		assertEquals EH_BOLSISTA_1, t.ehBolsista
		assertEquals PERIODO_1, t.periodo
	}
	
	
	void testConstraints(){
		def t = new Petiano(nome:NAME_1, sobrenome:SOBRENOME_1, login:LOGIN_1,
		password:PASSWORD_1, email:EMAIL_1, admission:ADMISSION_1, CRE:CRE_1, ehBolsista:EH_BOLSISTA_1, periodo:PERIODO_1)
		
		mockForConstraintsTests(Petiano,[t])
		assertTrue t.validate()
 
		def t2 = new Petiano(nome:NAME_1, sobrenome:SOBRENOME_1, login:LOGIN_1,
		password:PASSWORD_1, email:EMAIL_1, admission:ADMISSION_1, CRE:CRE_1, ehBolsista:EH_BOLSISTA_1, periodo:PERIODO_1)
	
		assertFalse t2.validate() 
		assertEquals "unique", t2.errors["login"]
		assertEquals "unique", t2.errors["email"]

		t = new Petiano()

		assertFalse t.validate() 
		assertEquals "nullable", t.errors["nome"] 
		assertEquals "nullable", t.errors["sobrenome"]
		assertEquals "nullable", t.errors["login"]
		assertEquals "nullable", t.errors["password"]
		assertEquals "nullable", t.errors["email"]
		assertEquals "nullable", t.errors["admission"]
		
	}
}
